package com.woniuxy.dudugua.test;

import com.woniuxy.dudugua.util.qnyutil.QiniuUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

@RestController
@RequestMapping("test")
public class FileUpLoad {
    @Autowired
    private QiniuUtil qiniuUtil;

    @RequestMapping("upload")
    public String fileUpload(MultipartFile file){
        String filename = file.getOriginalFilename();
        filename = "test/" + UUID.randomUUID().toString()+".jpg";
        try {
            qiniuUtil.upload(filename,file.getInputStream());
            String s = qiniuUtil.fullPath(filename);
            System.out.println(s);
        } catch (IOException e) {
            e.printStackTrace();
            return "error";
        }
        return "success";
    }
}
